package com.wander.patterns.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 享元工厂
 * @author: zhuyong
 * @create: 2019-09-07 16:11
 **/
public class FlyWeightFactory {
    //享元池
    private static Map<String,ChessFlyWeight> map= new HashMap<>();

    static ChessFlyWeight getChess(String color){
        if(map.containsKey(color)){
            return map.get(color);
        }else{
            ChessFlyWeight chessFlyWeight = new ConCreateChessFlyWeight(color);
            map.put(color,chessFlyWeight);
            return chessFlyWeight;
        }
    }
}
